package com.dao;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author 86152
 */
public interface MysqlDao {
    static DataSource getDataSouce(String datasourcename) throws NamingException {
        DataSource dataSource=null;
        try {
            Context context = new InitialContext();
            dataSource = (DataSource) context.lookup(datasourcename);
        }catch (NamingException e){
            System.out.println(e.getCause());
        }
        return dataSource;
    }
    default Connection getConnection(String datasourcename) throws NamingException, SQLException {
        DataSource dataSource=getDataSouce(datasourcename);
        Connection  connection=dataSource.getConnection();
        return connection;
    }
}
